package com.meixiang.adapter.myPurse;

import android.content.Context;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.meixiang.R;
import com.meixiang.entity.account.CashLogIndexInfos;
import com.meixiang.recyclerview.OnItemClick;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * 作者：zys  银行卡列表适配器
 */
public class BalanceIncomeRecordAdapter extends RecyclerView.Adapter<BalanceIncomeRecordAdapter.ContentViewHolder> {

    private List<CashLogIndexInfos> mDatas=new ArrayList<>();
    private Context context;

    public void clear(){
        this.mDatas.clear();
        this.notifyDataSetChanged();
    }
    public void addAll(List<CashLogIndexInfos> datas){
        this.mDatas.addAll(datas);
        this.notifyDataSetChanged();
    }
    public BalanceIncomeRecordAdapter(Context context) {
        this.context = context;
    }

    private OnItemClick onItemClickListener;

    public void setOnItemClickListener(OnItemClick onItemClickListener) {
        this.onItemClickListener = onItemClickListener;
    }

    @Override
    public ContentViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_item_income_record, parent, false);
        ContentViewHolder viewHolder = new ContentViewHolder(itemView);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(final ContentViewHolder holder, int position) {
        CashLogIndexInfos bean = mDatas.get(position);
        if (bean != null) {
            holder.tvIncomeType.setText(bean.getPdrType());
            holder.tvIncomeTimes.setText(bean.getPdrPaymentTime());
              if (bean.getPdrAmount().toString().substring(0,1).equals("-")){
                  holder.tvIncomeMoneys.setTextColor(ContextCompat.getColor(context,R.color.black_3));
                  holder.tvIncomeMoneys.setText(bean.getPdrAmount());
              }
            if (bean.getPdrAmount().toString().substring(0,1).equals("+")){
                holder.tvIncomeMoneys.setTextColor(ContextCompat.getColor(context,R.color.financial_green_text_color));
                holder.tvIncomeMoneys.setText(bean.getPdrAmount());
            }



            holder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    onItemClickListener.onItemClick(v, holder.getLayoutPosition());
                }
            });
        }
    }

    @Override
    public int getItemCount() {
        return mDatas == null ? 0 : mDatas.size();
    }

    static class ContentViewHolder extends RecyclerView.ViewHolder {
        @Bind(R.id.tv_income_type)
        TextView tvIncomeType;
        @Bind(R.id.tv_income_times)
        TextView tvIncomeTimes;
        @Bind(R.id.tv_income_moneys)
        TextView tvIncomeMoneys;

        public ContentViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }


}
